package algorithm.slidingWindow;

// 无重复字符的最长子串
public class LC3 {
    public int lengthOfLongestSubstring(String ss) {
        // 计数数组, 简易哈希表
        int[] hash = new int[128];
        char[] s = ss.toCharArray();
        int l = 0, r = 0, n = s.length, ans = 0;

        while (r < n) {
            hash[s[r]]++;
            if (hash[s[r]] == 1) {
                ans = Math.max(ans, r-l+1);
            }
            while (hash[s[r]] > 1)
                hash[s[l++]]--;
            r++;
        }
        return ans;
    }
}
